<template>
  <div>
    <el-dialog
      title="排序"
      :visible.sync="dialogVisible"
      width="600px"
      @closed="resetForm('form')"
    >
      <div>
        <el-form ref="form" :rules="rules" :model="form" label-width="120px">
          <el-form-item label="排序" prop="orderBy">
            <el-input-number
              v-model="form.orderBy"
              :min="1"
              :max="1000"
              size="medium"
              label="排序"
            ></el-input-number>
          </el-form-item>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button  type="custom" v-preventReClick  @click="submitForm('form')">提 交</el-button>
        <el-button @click="dialogVisible = false">取 消</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { sysCourseTeamUpdate } from "@/api/admin/courseLibrary/sysCourseTeam.js";
import Bus from "@/utils/bus.js";
export default {
  data() {
    return {
      dialogVisible: false,
      form: {
        id: "",
        orderBy: "",
      },
      rules: {
        orderBy: [{ required: true, message: "请输入序号", trigger: "blur" }],
      },
    };
  },
  mounted() {
    Bus.$on("showDialogCourseTeamSort", (v) => {
      this.form.id = v.id;
      this.form.orderBy = v.orderBy || 10;
      this.dialogVisible = true;
    });
  },
  beforeDestroy() {
    Bus.$off("showDialogCourseTeamSort");
  },
  methods: {
    submitForm(form) {
      this.$refs[form].validate((valid) => {
        if (valid) {
          this.audit();
        }
      });
    },
    //审核
    audit() {
      sysCourseTeamUpdate(this.form).then((res) => {
        if (res.data.code == 0) {
          this.dialogVisible = false;
          Bus.$emit("refreshCourseTeam");
          this.$message({
            message: "操作成功",
            type: "success",
          });
        }
      });
    },
    //重置表单
    resetForm(form) {
      this.$refs[form].resetFields();
      this.form.orderBy = "10";
    },
  },
};
</script>